<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Markdown 课程文章详情 | StudyRaid</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github-dark.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/4.3.0/marked.min.js"></script>
    <style>
        :root {
            --bg-primary: #0d1117;
            --bg-secondary: #161b22;
            --bg-tertiary: #21262d;
            --text-primary: #f0f6fc;
            --text-secondary: #c9d1d9;
            --text-tertiary: #8b949e;
            --border-color: #30363d;
            --accent-color: #58a6ff;
            --success-color: #3fb950;
            --warning-color: #d29922;
            --danger-color: #f85149;
            --border-radius: 6px;
            --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
        }

        body {
            background-color: var(--bg-primary);
            color: var(--text-primary);
            line-height: 1.5;
        }

        .container {
            max-width: 1280px;
            margin: 0 auto;
            padding: 0 20px;
        }

        /* 导航栏样式 */
        header {
            background-color: var(--bg-secondary);
            border-bottom: 1px solid var(--border-color);
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .navbar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 16px 0;
        }

        .logo {
            font-size: 24px;
            font-weight: 700;
            color: var(--text-primary);
            text-decoration: none;
            display: flex;
            align-items: center;
        }

        .logo i {
            margin-right: 10px;
            color: var(--accent-color);
        }

        .nav-links {
            display: flex;
            gap: 24px;
        }

        .nav-links a {
            color: var(--text-secondary);
            text-decoration: none;
            font-size: 14px;
            transition: color 0.2s;
        }

        .nav-links a:hover,
        .nav-links a.active {
            color: var(--text-primary);
        }

        .user-menu {
            display: flex;
            align-items: center;
            gap: 16px;
        }

        .search-box {
            position: relative;
        }

        .search-box input {
            background-color: var(--bg-tertiary);
            border: 1px solid var(--border-color);
            border-radius: var(--border-radius);
            padding: 8px 12px;
            padding-left: 32px;
            color: var(--text-primary);
            width: 240px;
            font-size: 14px;
        }

        .search-box i {
            position: absolute;
            left: 10px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--text-tertiary);
        }

        .user-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            background-color: var(--accent-color);
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            cursor: pointer;
        }

        /* 课程学习页面布局 */
        .course-learning-container {
            display: grid;
            grid-template-columns: 300px 1fr;
            gap: 24px;
            margin: 24px 0;
        }

        /* 侧边栏 */
        .course-sidebar {
            background-color: var(--bg-secondary);
            border-radius: var(--border-radius);
            border: 1px solid var(--border-color);
            overflow: hidden;
            height: fit-content;
            position: sticky;
            top: 90px;
        }

        .sidebar-header {
            padding: 16px;
            border-bottom: 1px solid var(--border-color);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .sidebar-title {
            font-size: 18px;
            font-weight: 600;
        }

        .progress-container {
            padding: 16px;
            border-bottom: 1px solid var(--border-color);
        }

        .progress-info {
            display: flex;
            justify-content: space-between;
            margin-bottom: 8px;
            font-size: 14px;
        }

        .progress-bar {
            height: 6px;
            background-color: var(--bg-tertiary);
            border-radius: 3px;
            overflow: hidden;
        }

        .progress-fill {
            height: 100%;
            background-color: var(--success-color);
            width: 65%;
        }

        .chapters-list {
            max-height: 500px;
            overflow-y: auto;
        }

        .chapter-item {
            border-bottom: 1px solid var(--border-color);
        }

        .chapter-item:last-child {
            border-bottom: none;
        }

        .chapter-header {
            padding: 12px 16px;
            background-color: var(--bg-tertiary);
            display: flex;
            justify-content: space-between;
            align-items: center;
            cursor: pointer;
        }

        .chapter-title {
            font-weight: 500;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .lessons-list {
            display: none;
            background-color: var(--bg-primary);
        }

        .lessons-list.active {
            display: block;
        }

        .lesson-item {
            padding: 12px 16px 12px 32px;
            border-bottom: 1px solid var(--border-color);
            display: flex;
            align-items: center;
            gap: 12px;
            cursor: pointer;
            transition: background-color 0.2s;
        }

        .lesson-item:hover {
            background-color: var(--bg-tertiary);
        }

        .lesson-item.active {
            background-color: var(--bg-tertiary);
            border-left: 3px solid var(--accent-color);
        }

        .lesson-item.completed .lesson-title {
            color: var(--success-color);
        }

        .lesson-item.completed .lesson-icon {
            color: var(--success-color);
        }

        .lesson-icon {
            width: 20px;
            text-align: center;
            color: var(--text-tertiary);
        }

        .lesson-title {
            flex: 1;
            font-size: 14px;
        }

        .lesson-duration {
            font-size: 12px;
            color: var(--text-tertiary);
        }

        /* 文章内容区域 */
        .article-content-area {
            background-color: var(--bg-secondary);
            border-radius: var(--border-radius);
            border: 1px solid var(--border-color);
            overflow: hidden;
            min-height: 600px;
        }

        .article-header {
            padding: 24px;
            border-bottom: 1px solid var(--border-color);
        }

        .article-title {
            font-size: 28px;
            font-weight: 600;
            margin-bottom: 12px;
        }

        .article-meta {
            display: flex;
            gap: 16px;
            color: var(--text-tertiary);
            font-size: 14px;
        }

        .article-body {
            padding: 24px;
            line-height: 1.7;
        }

        /* Markdown 样式 */
        .markdown-content h1,
        .markdown-content h2,
        .markdown-content h3,
        .markdown-content h4,
        .markdown-content h5,
        .markdown-content h6 {
            margin: 24px 0 16px;
            color: var(--text-primary);
            font-weight: 600;
        }

        .markdown-content h1 {
            font-size: 28px;
            border-bottom: 1px solid var(--border-color);
            padding-bottom: 8px;
        }

        .markdown-content h2 {
            font-size: 24px;
        }

        .markdown-content h3 {
            font-size: 20px;
        }

        .markdown-content p {
            margin-bottom: 16px;
            color: var(--text-secondary);
        }

        .markdown-content ul,
        .markdown-content ol {
            margin-bottom: 16px;
            padding-left: 24px;
            color: var(--text-secondary);
        }

        .markdown-content li {
            margin-bottom: 8px;
        }

        .markdown-content blockquote {
            border-left: 4px solid var(--accent-color);
            padding-left: 16px;
            margin: 16px 0;
            color: var(--text-tertiary);
            font-style: italic;
        }

        .markdown-content code {
            background-color: var(--bg-tertiary);
            padding: 2px 6px;
            border-radius: 4px;
            font-family: 'Courier New', monospace;
            font-size: 14px;
            color: var(--accent-color);
        }

        .markdown-content pre {
            background-color: var(--bg-tertiary);
            border-radius: var(--border-radius);
            padding: 16px;
            margin: 16px 0;
            overflow-x: auto;
        }

        .markdown-content pre code {
            background: none;
            padding: 0;
            color: inherit;
        }

        .markdown-content table {
            width: 100%;
            border-collapse: collapse;
            margin: 16px 0;
        }

        .markdown-content th,
        .markdown-content td {
            border: 1px solid var(--border-color);
            padding: 8px 12px;
            text-align: left;
        }

        .markdown-content th {
            background-color: var(--bg-tertiary);
            font-weight: 600;
        }

        .markdown-content a {
            color: var(--accent-color);
            text-decoration: none;
        }

        .markdown-content a:hover {
            text-decoration: underline;
        }

        .markdown-content img {
            max-width: 100%;
            border-radius: var(--border-radius);
            margin: 16px 0;
        }

        /* 文章底部操作 */
        .article-actions {
            padding: 20px 24px;
            border-top: 1px solid var(--border-color);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .btn {
            padding: 10px 20px;
            border-radius: var(--border-radius);
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            border: none;
            transition: all 0.2s;
            text-align: center;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }

        .btn-primary {
            background-color: var(--accent-color);
            color: white;
        }

        .btn-primary:hover {
            background-color: #4a93e0;
        }

        .btn-secondary {
            background-color: var(--bg-tertiary);
            color: var(--text-primary);
            border: 1px solid var(--border-color);
        }

        .btn-secondary:hover {
            background-color: var(--bg-secondary);
        }

        .btn-success {
            background-color: var(--success-color);
            color: white;
        }

        .btn-success:hover {
            background-color: #36a241;
        }

        /* 页脚 */
        footer {
            border-top: 1px solid var(--border-color);
            padding: 24px 0;
            margin-top: 40px;
            text-align: center;
            color: var(--text-tertiary);
            font-size: 14px;
        }

        /* 响应式设计 */
        @media (max-width: 1024px) {
            .course-learning-container {
                grid-template-columns: 1fr;
            }

            .course-sidebar {
                order: -1;
                position: static;
            }
        }

        @media (max-width: 768px) {
            .navbar {
                flex-direction: column;
                gap: 16px;
            }

            .nav-links {
                order: 3;
                width: 100%;
                justify-content: center;
            }

            .search-box input {
                width: 200px;
            }

            .article-actions {
                flex-direction: column;
                gap: 12px;
            }

            .article-actions .btn {
                width: 100%;
                justify-content: center;
            }
        }
    </style>
</head>

<body>
    <!-- 导航栏 -->
    <header>
        <div class="container">
            <nav class="navbar">
                <a href="#" class="logo">
                    <i class="fas fa-graduation-cap"></i>
                    StudyRaid
                </a>

                <div class="nav-links">
                    <a href="my-courses.html">我的课程</a>
                    <a href="explore.html">发现</a>
                    <a href="learning-path.html">学习路径</a>
                    <a href="progress-tracking.html" class="active">进度追踪</a>
                </div>

                <div class="user-menu">
                    <div class="search-box">
                        <i class="fas fa-search"></i>
                        <input type="text" placeholder="搜索课程...">
                    </div>
                    <div class="user-avatar">JS</div>
                </div>
            </nav>
        </div>
    </header>

    <!-- 课程学习内容 -->
    <main class="container">
        <div class="course-learning-container">
            <!-- 侧边栏 -->
            <div class="course-sidebar">
                <div class="sidebar-header">
                    <h3 class="sidebar-title">课程内容</h3>
                    <span class="progress-text">65% 完成</span>
                </div>

                <div class="progress-container">
                    <div class="progress-info">
                        <span>进度</span>
                        <span>13/20 节课</span>
                    </div>
                    <div class="progress-bar">
                        <div class="progress-fill"></div>
                    </div>
                </div>

                <div class="chapters-list">
                    <!-- 章节 1 -->
                    <div class="chapter-item">
                        <div class="chapter-header">
                            <div class="chapter-title">
                                <i class="fas fa-chevron-down"></i>
                                <span>第一章: JavaScript基础</span>
                            </div>
                            <span>4/4</span>
                        </div>
                        <div class="lessons-list active">
                            <div class="lesson-item completed" data-lesson="1">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">JavaScript简介与历史</div>
                                <div class="lesson-duration">阅读: 15分钟</div>
                            </div>
                            <div class="lesson-item completed" data-lesson="2">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">变量与数据类型</div>
                                <div class="lesson-duration">阅读: 22分钟</div>
                            </div>
                            <div class="lesson-item completed" data-lesson="3">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">运算符与表达式</div>
                                <div class="lesson-duration">阅读: 18分钟</div>
                            </div>
                            <div class="lesson-item completed" data-lesson="4">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">控制流程与循环</div>
                                <div class="lesson-duration">阅读: 25分钟</div>
                            </div>
                        </div>
                    </div>

                    <!-- 章节 2 -->
                    <div class="chapter-item">
                        <div class="chapter-header">
                            <div class="chapter-title">
                                <i class="fas fa-chevron-down"></i>
                                <span>第二章: 函数与作用域</span>
                            </div>
                            <span>3/4</span>
                        </div>
                        <div class="lessons-list">
                            <div class="lesson-item completed" data-lesson="5">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">函数定义与调用</div>
                                <div class="lesson-duration">阅读: 20分钟</div>
                            </div>
                            <div class="lesson-item completed" data-lesson="6">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">作用域与闭包</div>
                                <div class="lesson-duration">阅读: 28分钟</div>
                            </div>
                            <div class="lesson-item completed" data-lesson="7">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">高阶函数</div>
                                <div class="lesson-duration">阅读: 24分钟</div>
                            </div>
                            <div class="lesson-item" data-lesson="8">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">递归与柯里化</div>
                                <div class="lesson-duration">阅读: 19分钟</div>
                            </div>
                        </div>
                    </div>

                    <!-- 章节 3 -->
                    <div class="chapter-item">
                        <div class="chapter-header">
                            <div class="chapter-title">
                                <i class="fas fa-chevron-down"></i>
                                <span>第三章: 面向对象编程</span>
                            </div>
                            <span>3/5</span>
                        </div>
                        <div class="lessons-list">
                            <div class="lesson-item completed" data-lesson="9">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">对象与原型</div>
                                <div class="lesson-duration">阅读: 26分钟</div>
                            </div>
                            <div class="lesson-item completed" data-lesson="10">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">构造函数与类</div>
                                <div class="lesson-duration">阅读: 30分钟</div>
                            </div>
                            <div class="lesson-item completed" data-lesson="11">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">继承与多态</div>
                                <div class="lesson-duration">阅读: 22分钟</div>
                            </div>
                            <div class="lesson-item" data-lesson="12">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">设计模式应用</div>
                                <div class="lesson-duration">阅读: 35分钟</div>
                            </div>
                            <div class="lesson-item" data-lesson="13">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">模块化开发</div>
                                <div class="lesson-duration">阅读: 29分钟</div>
                            </div>
                        </div>
                    </div>

                    <!-- 章节 4 -->
                    <div class="chapter-item">
                        <div class="chapter-header">
                            <div class="chapter-title">
                                <i class="fas fa-chevron-down"></i>
                                <span>第四章: 异步编程</span>
                            </div>
                            <span>3/7</span>
                        </div>
                        <div class="lessons-list">
                            <div class="lesson-item completed" data-lesson="14">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">异步编程基础</div>
                                <div class="lesson-duration">阅读: 18分钟</div>
                            </div>
                            <div class="lesson-item completed" data-lesson="15">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">回调函数与事件循环</div>
                                <div class="lesson-duration">阅读: 32分钟</div>
                            </div>
                            <div class="lesson-item active" data-lesson="16">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">Promise与异步操作</div>
                                <div class="lesson-duration">阅读: 27分钟</div>
                            </div>
                            <div class="lesson-item" data-lesson="17">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">Async/Await语法</div>
                                <div class="lesson-duration">阅读: 24分钟</div>
                            </div>
                            <div class="lesson-item" data-lesson="18">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">错误处理与调试</div>
                                <div class="lesson-duration">阅读: 21分钟</div>
                            </div>
                            <div class="lesson-item" data-lesson="19">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">并发与性能优化</div>
                                <div class="lesson-duration">阅读: 29分钟</div>
                            </div>
                            <div class="lesson-item" data-lesson="20">
                                <div class="lesson-icon"><i class="fas fa-file-alt"></i></div>
                                <div class="lesson-title">实战项目: 异步数据加载</div>
                                <div class="lesson-duration">阅读: 45分钟</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 文章内容区域 -->
            <div class="article-content-area">
                <div class="article-header">
                    <h1 class="article-title">Promise与异步操作</h1>
                    <div class="article-meta">
                        <span><i class="far fa-clock"></i> 预计阅读时间: 27分钟</span>
                        <span><i class="far fa-calendar"></i> 最后更新: 2023-10-15</span>
                    </div>
                </div>
                <div class="article-body">
                    <div class="markdown-content" id="markdown-content">
                        <!-- Markdown内容将通过JavaScript动态加载 -->
                    </div>
                </div>
                <div class="article-actions">
                    <div class="navigation-buttons">
                        <button class="btn btn-secondary">
                            <i class="fas fa-arrow-left"></i> 上一节
                        </button>
                        <button class="btn btn-secondary">
                            下一节 <i class="fas fa-arrow-right"></i>
                        </button>
                    </div>
                    <button class="btn btn-primary" id="mark-complete-btn">
                        <i class="fas fa-check"></i> 标记为已完成
                    </button>
                </div>
            </div>
        </div>
    </main>

    <!-- 页脚 -->
    <footer>
        <div class="container">
            <p>© 2023 StudyRaid. 保留所有权利。</p>
            <p>采用 GitHub 深色风格设计</p>
        </div>
    </footer>

    <script>
        // 初始化代码高亮
        hljs.highlightAll();

        // 章节展开/折叠功能
        document.querySelectorAll('.chapter-header').forEach(header => {
            header.addEventListener('click', function () {
                const lessonsList = this.nextElementSibling;
                const icon = this.querySelector('i');

                if (lessonsList.classList.contains('active')) {
                    lessonsList.classList.remove('active');
                    icon.classList.remove('fa-chevron-down');
                    icon.classList.add('fa-chevron-right');
                } else {
                    lessonsList.classList.add('active');
                    icon.classList.remove('fa-chevron-right');
                    icon.classList.add('fa-chevron-down');
                }
            });
        });

        // 课程项点击功能
        document.querySelectorAll('.lesson-item').forEach(lesson => {
            lesson.addEventListener('click', function () {
                // 移除所有active类
                document.querySelectorAll('.lesson-item').forEach(item => {
                    item.classList.remove('active');
                });

                // 添加active类到当前项
                this.classList.add('active');

                // 更新文章标题和内容
                const title = this.querySelector('.lesson-title').textContent;
                document.querySelector('.article-title').textContent = title;

                // 加载对应的Markdown内容
                loadMarkdownContent(this.getAttribute('data-lesson'));
            });
        });

        // 模拟的Markdown内容
        const markdownContents = {
            1: `# JavaScript简介与历史\n\nJavaScript是一种高级的、解释型的编程语言。`,
            2: `# 变量与数据类型\n\nJavaScript有几种基本数据类型。`,
            // ... 其他课程内容
            16: `# Promise与异步操作

Promise是JavaScript中处理异步操作的一种强大方式。它代表一个异步操作的最终完成（或失败）及其结果值。

## 什么是Promise？

Promise是一个对象，它代表了一个异步操作的最终完成或失败。由于它的then方法返回一个新的Promise，所以可以链式调用。

### Promise的三种状态

1. **pending（待定）**：初始状态，既不是成功，也不是失败状态。
2. **fulfilled（已兑现）**：意味着操作成功完成。
3. **rejected（已拒绝）**：意味着操作失败。

## 创建Promise

\`\`\`javascript
const myPromise = new Promise((resolve, reject) => {
    // 异步操作
    setTimeout(() => {
        const success = true; // 模拟操作成功或失败
        
        if (success) {
            resolve('操作成功！');
        } else {
            reject('操作失败！');
        }
    }, 1000);
});
\`\`\`

## 使用Promise

\`\`\`javascript
myPromise
    .then(result => {
        console.log(result); // "操作成功！"
    })
    .catch(error => {
        console.error(error); // "操作失败！"
    })
    .finally(() => {
        console.log('操作完成'); // 无论成功或失败都会执行
    });
\`\`\`

## Promise链式调用

Promise的一个强大特性是能够链式调用：

\`\`\`javascript
function fetchUserData(userId) {
    return fetch(\`/api/users/\${userId}\`)
        .then(response => response.json())
        .then(user => {
            return fetch(\`/api/posts?userId=\${user.id}\`);
        })
        .then(response => response.json())
        .then(posts => {
            return { user, posts };
        })
        .catch(error => {
            console.error('获取数据失败:', error);
        });
}
\`\`\`

## Promise.all()

当需要等待多个Promise都完成时，可以使用Promise.all()：

\`\`\`javascript
const promise1 = Promise.resolve(3);
const promise2 = 42;
const promise3 = new Promise((resolve, reject) => {
    setTimeout(resolve, 100, 'foo');
});

Promise.all([promise1, promise2, promise3]).then(values => {
    console.log(values); // [3, 42, "foo"]
});
\`\`\`

## Promise.race()

Promise.race()方法返回一个Promise，一旦迭代器中的某个Promise解决或拒绝，返回的Promise就会解决或拒绝：

\`\`\`javascript
const promise1 = new Promise((resolve, reject) => {
    setTimeout(resolve, 500, 'one');
});

const promise2 = new Promise((resolve, reject) => {
    setTimeout(resolve, 100, 'two');
});

Promise.race([promise1, promise2]).then(value => {
    console.log(value); // "two" - 因为promise2更快完成
});
\`\`\`

## 实际应用示例

以下是一个使用Promise处理多个异步操作的示例：

\`\`\`javascript
function loadUserProfile(userId) {
    return Promise.all([
        fetchUser(userId),
        fetchUserPosts(userId),
        fetchUserFriends(userId)
    ]).then(([user, posts, friends]) => {
        return {
            user,
            posts,
            friends
        };
    });
}

// 使用示例
loadUserProfile(123)
    .then(profile => {
        console.log('用户资料:', profile);
        renderProfile(profile);
    })
    .catch(error => {
        console.error('加载用户资料失败:', error);
        showErrorMessage('无法加载用户资料');
    });
\`\`\`

## 总结

Promise是JavaScript异步编程的核心概念之一，它解决了回调地狱的问题，使异步代码更加清晰和易于维护。在现代JavaScript开发中，Promise与async/await结合使用，可以编写出更加优雅的异步代码。

在下一节中，我们将学习async/await语法，这是基于Promise的语法糖，使异步代码看起来更像同步代码。`
            // ... 其他课程内容
        };

        // 加载Markdown内容
        function loadMarkdownContent(lessonId) {
            const markdownContent = markdownContents[lessonId] || '# 内容加载中...';
            const htmlContent = marked.parse(markdownContent);
            document.getElementById('markdown-content').innerHTML = htmlContent;

            // 重新高亮代码块
            document.querySelectorAll('pre code').forEach(block => {
                hljs.highlightElement(block);
            });
        }

        // 初始加载当前课程内容
        loadMarkdownContent(16);

        // 标记完成功能
        document.getElementById('mark-complete-btn').addEventListener('click', function () {
            const activeLesson = document.querySelector('.lesson-item.active');
            if (activeLesson && !activeLesson.classList.contains('completed')) {
                activeLesson.classList.add('completed');
                this.innerHTML = '<i class="fas fa-check-double"></i> 已完成';
                this.classList.remove('btn-primary');
                this.classList.add('btn-success');

                // 更新进度
                const progressFill = document.querySelector('.progress-fill');
                const currentWidth = parseInt(progressFill.style.width) || 65;
                const newWidth = Math.min(currentWidth + 5, 100);
                progressFill.style.width = newWidth + '%';

                // 更新进度文本
                const progressText = document.querySelector('.progress-text');
                progressText.textContent = newWidth + '% 完成';

                // 更新进度计数
                const progressInfo = document.querySelector('.progress-info span:last-child');
                const currentCount = progressInfo.textContent.split('/')[0];
                const totalCount = progressInfo.textContent.split('/')[1];
                const newCount = parseInt(currentCount) + 1;
                progressInfo.textContent = newCount + '/' + totalCount;

                // 更新章节完成数
                const chapterHeader = activeLesson.closest('.chapter-item').querySelector('.chapter-header span');
                const chapterCount = chapterHeader.textContent.split('/');
                const completed = parseInt(chapterCount[0]) + 1;
                const total = parseInt(chapterCount[1]);
                chapterHeader.textContent = completed + '/' + total;
            }
        });

        // 导航按钮功能
        document.querySelectorAll('.navigation-buttons .btn').forEach(button => {
            button.addEventListener('click', function () {
                const activeLesson = document.querySelector('.lesson-item.active');
                const lessonId = parseInt(activeLesson.getAttribute('data-lesson'));
                let targetLessonId;

                if (this.textContent.includes('上一节')) {
                    targetLessonId = lessonId - 1;
                } else {
                    targetLessonId = lessonId + 1;
                }

                const targetLesson = document.querySelector(`.lesson-item[data-lesson="${targetLessonId}"]`);
                if (targetLesson) {
                    targetLesson.click();
                    // 滚动到目标课程项
                    targetLesson.scrollIntoView({ behavior: 'smooth', block: 'center' });
                }
            });
        });
    </script>
</body>

</html>